package com.heima.admin.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.IAdChannelService;
import com.heima.media.entity.WmChannel;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UpdateChannlListener {
    @Autowired
    private IAdChannelService adChannelService;
    @KafkaListener(topics = "update_channel")
    public void updateChannelListener(ConsumerRecord<String,String> consumerRecord){
        String value = consumerRecord.value();
        WmChannel wmChannel = JSON.parseObject(value, WmChannel.class);
        System.out.println("admin端监听到修改数据了"+wmChannel);
        adChannelService.updateChannel(wmChannel);  //更新时修改admin数据库中的channel表
    }
}
